module.exports = app => {
  const express = require('express')
  const router = express.Router()
  const http = require('request')
  app.use(express.json()) // 使用json

  // 查询单个
  router.get('/:id', async (req, res) => {
    const data = {
      perception: {
        inputText: {
          text: req.query.msg
        }
      },
      userInfo: {
        apiKey: '61d2ef6a5c38407f8d58df05ea992df7',
        userId: req.params.id
      }
    }
    http({
      url: 'http://openapi.turingapi.com/openapi/api/v2',
      method: "POST",
      json: true,
      headers: {
          "content-type": "application/json",
      },
      body: data
    }, function(error, response, body) {
      if (!error && response.statusCode == 200) {
        res.send({
          code: 0,
          msg: 'success',
          data: body.results
        })
      }
    })
  })

  app.use('/node/adaptor', router)
}
